<html xmlns="http://www.w3.org/1999/xhtml" >
<%@ page language="java" import	="java.io.*,java.sql.*" %>

<%@include file="../dbcon.jsp"%>
<%
	int iMsgId = 1; 
	int iSno = 0;
	int iRecType = 0;
	
	String sOwnerName = "",sTitle = "",sLocation = "",sLot = "",sLandTaxNo = "",sWaterzone = "";
	String sPrice = "",sAddress = "" ,sMobile = "",sEmail = "",sLandline = "",sDesc = "";
	int iLandType = 0;
			
	String sTmp = request.getParameter("hid_RecType");
	if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
		iRecType = Integer.parseInt(sTmp);
	
	sTmp = request.getParameter("hid_RecSno");
	if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
		iSno = Integer.parseInt(sTmp);
//System.out.println("iSno : "+ iSno);			
	if ( sTmp == null || sTmp.equals("null") || sTmp.equals("") )
	{
		response.sendRedirect("frm_land.jsp");
		//System.out.println("sTmp : "+ sTmp);				
		return;
	}
	
	iLandType = Integer.parseInt( request.getParameter("cb_landtype") );
	sTitle = request.getParameter("txt_title");
	sOwnerName = request.getParameter("txt_ownername");	
	sLocation = request.getParameter("txt_location");	
	sLot = request.getParameter("txt_lot");
	sLandTaxNo = request.getParameter("txt_landtaxno");
	sWaterzone = request.getParameter("txt_waterzone");
	sPrice = request.getParameter("txt_price");
	sAddress = request.getParameter("ta_address");	
	sMobile = request.getParameter("txt_mobile");
	sLandline = request.getParameter("txt_landline");	
	sEmail = request.getParameter("txt_email");
	sDesc = request.getParameter("ta_desc");
	
	try{		
		String sRtnMsg = "";
		if ( iRecType == 1 )
		{
			String sQry = "insert into tbl_rel_land(land_type,owner_name,location,lot,";
			sQry += "land_tax_no ,water_zarea ,price ,mobile ,landline ,email,";
			sQry += "address,title,description ) values(";
			sQry += iLandType + ",'"+ sOwnerName +"','"+ sLocation +"',";
			sQry += "'"+ sLot +"','"+ sLandTaxNo +"','"+ sWaterzone +"',"+ sPrice ;
			sQry += ",'"+ sMobile +"','" + sLandline +"','"+ sEmail +"','"+ sAddress +"',";
			sQry += "'"+ sTitle +"','"+ sDesc +"'";
			sQry += ")";
			
		System.out.println("tbl_rel_land Qry : "+ sQry);					

			Statement Stmt = Con.createStatement();
			Stmt.executeUpdate(sQry);
			if ( Stmt != null ) Stmt.close();

			iMsgId = 1;
			System.out.println("Insert Successfully");
		}
		else if ( iRecType == 2)
		{
			String sQry = "update tbl_rel_land set ";
			sQry += "land_type="+ iLandType +",";
			sQry += "owner_name='"+ sOwnerName +"',";
			sQry += "location='"+ sLocation +"',";
			sQry += "lot='"+ sLot +"',";			
			sQry += "land_tax_no='"+ sLandTaxNo +"',";
			sQry += "water_zarea='"+ sWaterzone +"',";
			sQry += "price="+ sPrice +",";			
			sQry += "mobile='"+ sMobile +"',";
			sQry += "landline='"+ sLandline +"',";
			sQry += "email='"+ sEmail +"',";
			sQry += "address='"+ sAddress +"',";
			sQry += "title='"+ sTitle +"',";
			sQry += "description='"+ sDesc +"'";
			sQry += " where id="+ iSno;
		System.out.println("tbl_rel_land Qry : "+ sQry);					
		
			Statement Stmt = Con.createStatement();
			Stmt.executeUpdate(sQry);
			if ( Stmt != null ) Stmt.close();
					
			iMsgId = 3;
			System.out.println("Update Successfully");
		}
	}
	catch(Exception e)
	{	
		System.out.println("Failed : "+ e);	
		if ( iRecType == 1 ) iMsgId = 2;
		else iMsgId = 4;
	}
	
	if ( Con != null ) Con.close();
	response.sendRedirect("../frm_msg.jsp?MsgID="+ iMsgId);
	//System.out.println("Insert Failed");
%>
</html>